﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using TestManagerClient.Model;

namespace TestManagerClient.Pages
{
    /// <summary>
    /// Interaction logic for AddCourse.xaml
    /// </summary>
    public partial class AddCourse : Page
    {
        
        public Courses _Course { get; set; }

        public AddCourse()
        {
            InitializeComponent();

            titleTextBlock.Text = "Stwórz nowy kurs";

            InformationDisplay.HideNotification(notificationGrid, notificationTextBlock);
            InformationDisplay.HideWarning(warningGrid, warningTextBlock);
            InformationDisplay.HideError(errorGrid, errorTextBlock);

           
           
           
        }

        #region Metody obsługujące przyciski zamknięcia informacji

        private void closeNotificationGridButton_Click(object sender, RoutedEventArgs e)
        {
            InformationDisplay.HideNotification(notificationGrid, notificationTextBlock);
        }

        private void closeWarningGridButton_Click(object sender, RoutedEventArgs e)
        {
            InformationDisplay.HideWarning(warningGrid, warningTextBlock);
        }

        private void closeErrorGridButton_Click(object sender, RoutedEventArgs e)
        {
            InformationDisplay.HideError(errorGrid, errorTextBlock);
        }


        #endregion

        private void btn_SaveCourse_Click_1(object sender, RoutedEventArgs e)
        {
            if (txt_CourseName.Text != "" && txt_CourseDescription.Text != "")
            {
                if (_Course == null)
                {
                    Courses course = new Courses();
                    course.Name = txt_CourseName.Text;
                    course.Description = txt_CourseDescription.Text;
                    JoinToCourse.CoursesList.Add(course);

                }
                else
                {
                    var _course = JoinToCourse.CoursesList.Where(p => p.Name == _Course.Name).First();
                    _course.Name = txt_CourseName.Text;
                    _course.Description = txt_CourseDescription.Text;
                }
                
                //InformationDisplay.ShowNotification("Zapisano kurs", notificationGrid, notificationTextBlock);
                System.Threading.Thread.Sleep(150);
                btn_SaveCourse.Command = NavigationCommands.GoToPage;
                btn_SaveCourse.CommandParameter = "Pages/CoursesPage.xaml";
            }
            else
            {
                InformationDisplay.ShowError("Nie wypełniono wszystkich danych", errorGrid, errorTextBlock);
            }
           
        }

        private void btn_Close_Click_1(object sender, RoutedEventArgs e)
        {
            btn_Close.Command = NavigationCommands.GoToPage;
            btn_Close.CommandParameter = "Pages/CoursesPage.xaml";
        }

    
    }
}
